package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CsSalesRecord;
import com.ruoyi.system.service.ICsSalesRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出售记录Controller
 * 
 * @author ruoyi
 * @date 2025-10-05
 */
@Controller
@RequestMapping("/system/sales")
public class CsSalesRecordController extends BaseController
{
    private String prefix = "system/sales";

    @Autowired
    private ICsSalesRecordService csSalesRecordService;

    @GetMapping()
    public String salesRecord()
    {
        return prefix + "/record";
    }

    /**
     * 查询出售记录列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CsSalesRecord csSalesRecord)
    {
        startPage();
        List<CsSalesRecord> list = csSalesRecordService.selectCsSalesRecordList(csSalesRecord);
        return getDataTable(list);
    }

    /**
     * 导出出售记录列表
     */
    @Log(title = "出售记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CsSalesRecord csSalesRecord)
    {
        List<CsSalesRecord> list = csSalesRecordService.selectCsSalesRecordList(csSalesRecord);
        ExcelUtil<CsSalesRecord> util = new ExcelUtil<CsSalesRecord>(CsSalesRecord.class);
        return util.exportExcel(list, "出售记录数据");
    }

    /**
     * 新增出售记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存出售记录
     */
    @Log(title = "出售记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CsSalesRecord csSalesRecord)
    {
        return toAjax(csSalesRecordService.insertCsSalesRecord(csSalesRecord));
    }

    /**
     * 修改出售记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CsSalesRecord csSalesRecord = csSalesRecordService.selectCsSalesRecordById(id);
        mmap.put("csSalesRecord", csSalesRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存出售记录
     */
    @Log(title = "出售记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CsSalesRecord csSalesRecord)
    {
        return toAjax(csSalesRecordService.updateCsSalesRecord(csSalesRecord));
    }

    /**
     * 删除出售记录
     */
    @Log(title = "出售记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(csSalesRecordService.deleteCsSalesRecordByIds(ids));
    }
}
